package cz.cvut.fit.mi.dpo.mvc.view.tables;

import cz.cvut.fit.mi.dpo.mvc.controller.Controller;
import cz.cvut.fit.mi.dpo.mvc.model.IReadable;
import cz.cvut.fit.mi.dpo.mvc.view.AView;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JPanel;

/**
 * @author David Pertl
 * @author Martin Štekl <steklmar@fit.cvut.cz>
 */
public class TableView extends AView {

	public TableView(Controller controller, IReadable model) {
		super(controller, model);
		setLayout(new GridLayout(3, 1));

		JButton clearButton = new JButton("Clear all");
		clearButton.addMouseListener(
			new MouseAdapter() {
				public void mouseClicked(MouseEvent event) {
					clearAll();
				}
			}
		);

		JPanel jp = new JPanel();
		jp.setPreferredSize(new Dimension(100, 30));
		jp.add(clearButton);

		setPreferredSize(new Dimension(400, 0));

		add(new CircleTable(controller, model, "Circles"));
		add(new SquareTable(controller, model, "Squares"));
		add(jp);
	}

	private void clearAll() {
		controller.clearAll();
	}

}
